package com.surprise.biz.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import redis.clients.jedis.Jedis;

import com.surprise.biz.bo.SNSBO;
import com.surprise.biz.service.StoreService;
import com.surprise.redis.RedisFactory;

/**
 * StoreManager.java
 * @author nick
 * 2015年2月13日
 */
@Component
public class StoreManager {
    @Autowired
    private StoreService storeService;

    @Autowired
    private RedisFactory redisFactory;

    public int add(SNSBO bo) {
        Jedis jedis = null;
        try {
            jedis = redisFactory.getClient();
            if (bo.getStatus() == 1) {
                return storeService.add(jedis, bo);
            }
            return storeService.del(jedis, bo);
        } finally {
            redisFactory.returnResource(jedis);
        }
    }
    
    public int dump(int batch) {
        Jedis jedis = null;
        try {
            jedis = redisFactory.getClient();
            int ret = storeService.dump(jedis, batch);
            return ret;
        } finally {
            redisFactory.returnResource(jedis);
        }
    }
}
